package com.news.model;

import java.time.LocalDateTime;
import java.util.List;
import java.util.ArrayList;

/**
 * 文章内容数据模型
 */
public class ArticleContent {
    private String title;           // 文章标题
    private String content;         // 文章正文内容
    private String summary;         // 文章摘要
    private String author;          // 作者
    private LocalDateTime publishTime; // 发布时间
    private String sourceUrl;       // 原文链接
    private List<ArticleImage> images; // 文章图片列表
    private String htmlContent;     // 格式化的HTML内容
    private boolean extractSuccess; // 是否提取成功
    private String errorMessage;    // 错误信息

    public ArticleContent() {
        this.images = new ArrayList<>();
        this.extractSuccess = false;
    }

    public ArticleContent(String title, String content) {
        this();
        this.title = title;
        this.content = content;
        this.extractSuccess = true;
    }

    // Getters and Setters
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getSummary() {
        return summary;
    }

    public void setSummary(String summary) {
        this.summary = summary;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public LocalDateTime getPublishTime() {
        return publishTime;
    }

    public void setPublishTime(LocalDateTime publishTime) {
        this.publishTime = publishTime;
    }

    public String getSourceUrl() {
        return sourceUrl;
    }

    public void setSourceUrl(String sourceUrl) {
        this.sourceUrl = sourceUrl;
    }

    public List<ArticleImage> getImages() {
        return images;
    }

    public void setImages(List<ArticleImage> images) {
        this.images = images != null ? images : new ArrayList<>();
    }

    public void addImage(ArticleImage image) {
        if (image != null && images != null) {
            images.add(image);
        }
    }

    public String getHtmlContent() {
        return htmlContent;
    }

    public void setHtmlContent(String htmlContent) {
        this.htmlContent = htmlContent;
    }

    public boolean isExtractSuccess() {
        return extractSuccess;
    }

    public void setExtractSuccess(boolean extractSuccess) {
        this.extractSuccess = extractSuccess;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    /**
     * 获取主要图片（第一张图片）
     */
    public ArticleImage getMainImage() {
        return images != null && !images.isEmpty() ? images.get(0) : null;
    }

    /**
     * 获取图片数量
     */
    public int getImageCount() {
        return images != null ? images.size() : 0;
    }

    /**
     * 检查是否有图片
     */
    public boolean hasImages() {
        return getImageCount() > 0;
    }

    /**
     * 获取内容长度
     */
    public int getContentLength() {
        return content != null ? content.length() : 0;
    }

    @Override
    public String toString() {
        return "ArticleContent{" +
                "title='" + title + '\'' +
                ", contentLength=" + getContentLength() +
                ", imageCount=" + getImageCount() +
                ", extractSuccess=" + extractSuccess +
                '}';
    }
} 